#ifndef DACAI_USER_H_
#define DACAI_USER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "code/inc/config.h"


#define NOTIFY_TOUCH_PRESS         0X01  //触摸屏按下通知
#define NOTIFY_TOUCH_RELEASE       0X03  //触摸屏松开通知
#define NOTIFY_WRITE_FLASH_OK      0X0C  //写FLASH成功
#define NOTIFY_WRITE_FLASH_FAILD   0X0D  //写FLASH失败
#define NOTIFY_READ_FLASH_OK       0X0B  //读FLASH成功
#define NOTIFY_READ_FLASH_FAILD    0X0F  //读FLASH失败
#define NOTIFY_MENU                0X14  //菜单事件通知
#define NOTIFY_TIMER               0X43  //定时器超时通知
#define NOTIFY_CONTROL             0XB1  //控件更新通知
#define NOTIFY_READ_RTC            0XF7  //读取RTC时间
#define MSG_GET_CURRENT_SCREEN     0X01  //画面ID变化通知
#define MSG_GET_DATA               0X11  //控件数据通知
#define NOTIFY_HandShake           0X55  //握手通知

#define PTR2U16(PTR) ((((uint8 *)(PTR))[0]<<8)|((uint8 *)(PTR))[1])  //从缓冲区取16位数据
#define PTR2U32(PTR) ((((uint8 *)(PTR))[0]<<24)|(((uint8 *)(PTR))[1]<<16)|(((uint8 *)(PTR))[2]<<8)|((uint8 *)(PTR))[3])  //从缓冲区取32位数据

enum CtrlType
{
    kCtrlUnknown=0x0,
    kCtrlButton=0x10,                     //按钮
    kCtrlText,                            //文本
    kCtrlProgress,                        //进度条
    kCtrlSlider,                          //滑动条
    kCtrlMeter,                            //仪表
    kCtrlDropList,                        //下拉列表
    kCtrlAnimation,                       //动画
    kCtrlRTC,                             //时间显示
    kCtrlGraph,                           //曲线图控件
    kCtrlTable,                           //表格控件
    kCtrlMenu,                            //菜单控件
    kCtrlSelector,                        //选择控件
    kCtrlQRCode,                          //二维码
};

#pragma pack(push)
#pragma pack(1)                           //按字节对齐

typedef struct
{
    uint8    cmd_head;                    //帧头

    uint8    cmd_type;                    //命令类型(UPDATE_CONTROL)
    uint8    ctrl_msg;                    //CtrlMsgType-指示消息的类型
    uint16   screen_id;                   //产生消息的画面ID
    uint16   control_id;                  //产生消息的控件ID
    uint8    control_type;                //控件类型

    uint8    param[256];                  //可变长度参数，最多256个字节

    uint8  cmd_tail[4];                   //帧尾
}CTRL_MSG,*PCTRL_MSG;

typedef void (*NOTIFYHandShak) (void);//握手通知
typedef void (*NotifyScreen)(uint16);//画面切换通知
typedef void (*NotifyButton)(uint16,uint16,uint8);//按钮控件通知
typedef void (*NotifyText)(uint16,uint16,uint8 *);//文本通知信息
typedef void (*NotifyProgress)(uint16,uint16,uint32);//进度条通知
typedef void (*NotifySlider)(uint16,uint16,uint16);//滑块条控件
typedef void (*NotifyMeter)(uint16,uint16,uint16);//仪表盘控件
typedef void (*NotifyMenu)(uint16,uint16,uint8,uint8);//菜单控件
typedef void (*NotifySelector)(uint16,uint16,uint8);//选择控件
typedef void (*NotifyTimer)(uint16,uint16);//倒计时控件
typedef void (*NotifyReadRTC)(uint8,uint8,uint8,uint8,uint8,uint8,uint8);//rtc时间读取通知

#define CMD_MAX_SIZE 64

struct t_driver
{
   uint8  cmd_buffer[CMD_MAX_SIZE];
   NOTIFYHandShak _NOTIFYHandShak;
   NotifyScreen _NotifyScreen;
   NotifyButton _NotifyButton;
   NotifyText _NotifyText;
   NotifyProgress _NotifyProgress;
   NotifySlider _NotifySlider;
   NotifyMeter _NotifyMeter;
   NotifyMenu _NotifyMenu;
   NotifySelector _NotifySelector;
   NotifyTimer _NotifyTimer;
   NotifyReadRTC _NotifyReadRTC;
};

#pragma pack(pop)

void driver_init(struct t_driver *driver);
void driver_poll(void);

#ifdef __cplusplus
}
#endif

#endif
